<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="&amp;#x524D;&amp;#x63D0; 1&amp;#x3001;&amp;#x5404;&amp;#x4F4D;&amp;#x770B;&amp;#x5B98;&amp;#x5927;&amp;#x5BB6;&amp;#x597D;&amp;#xFF0C;&amp;#x5C0F;&amp;#x53EF;&amp;#x4ECA;&amp;#x5929;&amp;#x53C8;&amp;#x6765;&amp;#x88C5;&amp;#xFF0C;&amp;#x554A;&amp;#x5478;&amp;#xFF0C;&amp;#x53C8;&amp;#x6765;&amp;#x519">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 自定义接口">
<meta property="og:url" content="http://yoursite.com/2019/08/21/Android 自定义接口/index.html">
<meta property="og:site_name" content="Silence潇湘夜雨">
<meta property="og:description" content="&amp;#x524D;&amp;#x63D0; 1&amp;#x3001;&amp;#x5404;&amp;#x4F4D;&amp;#x770B;&amp;#x5B98;&amp;#x5927;&amp;#x5BB6;&amp;#x597D;&amp;#xFF0C;&amp;#x5C0F;&amp;#x53EF;&amp;#x4ECA;&amp;#x5929;&amp;#x53C8;&amp;#x6765;&amp;#x88C5;&amp;#xFF0C;&amp;#x554A;&amp;#x5478;&amp;#xFF0C;&amp;#x53C8;&amp;#x6765;&amp;#x519">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1716569-036829b6b279f332.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2019-07-19T05:33:19.291Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android 自定义接口">
<meta name="twitter:description" content="&amp;#x524D;&amp;#x63D0; 1&amp;#x3001;&amp;#x5404;&amp;#x4F4D;&amp;#x770B;&amp;#x5B98;&amp;#x5927;&amp;#x5BB6;&amp;#x597D;&amp;#xFF0C;&amp;#x5C0F;&amp;#x53EF;&amp;#x4ECA;&amp;#x5929;&amp;#x53C8;&amp;#x6765;&amp;#x88C5;&amp;#xFF0C;&amp;#x554A;&amp;#x5478;&amp;#xFF0C;&amp;#x53C8;&amp;#x6765;&amp;#x519">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/1716569-036829b6b279f332.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/08/21/Android 自定义接口/">





  <title>Android 自定义接口 | Silence潇湘夜雨</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Silence潇湘夜雨</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Android开发一枚</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home //首页"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user //关于"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags  //标签"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th //分类"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive //归档"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-schedule">
          <a href="/schedule/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-calendar //日程表"></i> <br>
            
            日程表
          </a>
        </li>
      
        
        <li class="menu-item menu-item-sitemap">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap //站点地图"></i> <br>
            
            站点地图
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/08/21/Android 自定义接口/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Silence潇湘夜雨">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Silence潇湘夜雨">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android 自定义接口</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-08-21T15:51:43+08:00">
                2019-08-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android/" itemprop="url" rel="index">
                    <span itemprop="name">Android</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.4k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  8
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="&#x524D;&#x63D0;"><a href="#&#x524D;&#x63D0;" class="headerlink" title="&#x524D;&#x63D0;"></a>&#x524D;&#x63D0;</h3><p> <strong>1&#x3001;&#x5404;&#x4F4D;&#x770B;&#x5B98;&#x5927;&#x5BB6;&#x597D;&#xFF0C;&#x5C0F;&#x53EF;&#x4ECA;&#x5929;&#x53C8;&#x6765;&#x88C5;&#xFF0C;&#x554A;&#x5478;&#xFF0C;&#x53C8;&#x6765;&#x5199;&#x5E72;&#x8D27;&#x6765;&#x4E86;&#x3002;&#x5728;&#x81EA;&#x5B9A;&#x4E49;Android&#x63A5;&#x53E3;&#x4E4B;&#x524D;&#x5148;&#x8981;&#x641E;&#x6E05;&#x695A;&#x4EC0;&#x4E48;&#x662F;&#x63A5;&#x53E3;</strong><br><strong>2&#x3001;&#x63A5;&#x53E3;&#x5B9A;&#x4E49;</strong></p>
<ul>
<li><p>&#x5927;&#x5BB6;&#x90FD;&#x77E5;&#x9053;Android&#x662F;&#x57FA;&#x4E8E;Java&#x8BED;&#x8A00;&#x5F00;&#x53D1;&#x7684;&#xFF0C;&#x55EF;&#xFF0C;&#x4E4B;&#x524D;&#x662F;&#xFF0C;&#x5F53;&#x7136;&#x73B0;&#x5728;&#x4E5F;&#x6709;Kotin&#xFF0C;&#x4ECA;&#x5929;&#x4E3B;&#x8981;&#x8BB2;&#x89E3;Java&#x65B9;&#x9762;&#x3002;</p>
<ul>
<li>&#x63A5;&#x53E3;&#xFF08;&#x82F1;&#x6587;&#xFF1A;Interface&#xFF09;&#xFF0C;&#x5728;JAVA&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x4E2D;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x578B;&#xFF0C;&#x662F;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x7684;&#x96C6;&#x5408;&#xFF0C;&#x63A5;&#x53E3;&#x901A;&#x5E38;&#x4EE5;interface&#x6765;&#x58F0;&#x660E;&#x3002;&#x4E00;&#x4E2A;&#x7C7B;&#x901A;&#x8FC7;&#x7EE7;&#x627F;&#x63A5;&#x53E3;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x4ECE;&#x800C;&#x6765;&#x7EE7;&#x627F;&#x63A5;&#x53E3;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x3002;</li>
<li>&#x63A5;&#x53E3;&#x5E76;&#x4E0D;&#x662F;&#x7C7B;&#xFF0C;&#x7F16;&#x5199;&#x63A5;&#x53E3;&#x7684;&#x65B9;&#x5F0F;&#x548C;&#x7C7B;&#x5F88;&#x76F8;&#x4F3C;&#xFF0C;&#x4F46;&#x662F;&#x5B83;&#x4EEC;&#x5C5E;&#x4E8E;&#x4E0D;&#x540C;&#x7684;&#x6982;&#x5FF5;&#x3002;&#x7C7B;&#x63CF;&#x8FF0;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x3002;&#x63A5;&#x53E3;&#x5219;&#x5305;&#x542B;&#x7C7B;&#x8981;&#x5B9E;&#x73B0;&#x7684;&#x65B9;&#x6CD5;&#x3002;&#x9664;&#x975E;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x7684;&#x7C7B;&#x662F;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x5426;&#x5219;&#x8BE5;&#x7C7B;&#x8981;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x65B9;&#x6CD5;&#x3002;</li>
<li>&#x63A5;&#x53E3;&#x65E0;&#x6CD5;&#x88AB;&#x5B9E;&#x4F8B;&#x5316;&#xFF0C;&#x4F46;&#x662F;&#x53EF;&#x4EE5;&#x88AB;&#x5B9E;&#x73B0;&#x3002;&#x4E00;&#x4E2A;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x7684;&#x7C7B;&#xFF0C;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x5185;&#x6240;&#x63CF;&#x8FF0;&#x7684;&#x6240;&#x6709;&#x65B9;&#x6CD5;&#xFF0C;&#x5426;&#x5219;&#x5C31;&#x5FC5;&#x987B;&#x58F0;&#x660E;&#x4E3A;&#x62BD;&#x8C61;&#x7C7B;&#x3002;&#x53E6;&#x5916;&#xFF0C;&#x5728; Java &#x4E2D;&#xFF0C;&#x63A5;&#x53E3;&#x7C7B;&#x578B;&#x53EF;&#x7528;&#x6765;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x4ED6;&#x4EEC;&#x53EF;&#x4EE5;&#x6210;&#x4E3A;&#x4E00;&#x4E2A;&#x7A7A;&#x6307;&#x9488;&#xFF0C;&#x6216;&#x662F;&#x88AB;&#x7ED1;&#x5B9A;&#x5728;&#x4E00;&#x4E2A;&#x4EE5;&#x6B64;&#x63A5;&#x53E3;&#x5B9E;&#x73B0;&#x7684;&#x5BF9;&#x8C61;&#x3002;</li>
</ul>
<p><strong>3&#x3001;&#x5B9E;&#x73B0;&#x65B9;&#x6CD5;</strong></p>
<ul>
<li>&#x76F8;&#x4FE1;&#x4E0A;&#x9762;&#x5BF9;&#x63A5;&#x53E3;&#x7684;&#x8BF4;&#x660E;&#x5927;&#x5BB6;&#x90FD;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#xFF0C;&#x4F46;&#x662F;&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x53C8;&#x662F;&#x4EC0;&#x4E48;&#x6837;&#x5B50;&#x7684;&#x5462;&#xFF0C;&#x76F8;&#x4FE1;&#x8FD8;&#x662F;&#x6BD4;&#x8F83;&#x62BD;&#x8C61;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4ECA;&#x5929;&#x5C31;&#x5C0F;&#x53EF;&#x5C31;&#x5728;&#x6B64;&#x4E3E;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x6765;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;<br>###&#x9996;&#x5148;</li>
</ul>
</li>
<li><p>&#x5148;&#x5206;&#x6790;&#x4E00;&#x4E0B;&#xFF0C;&#x6211;&#x4EEC;&#x4ECA;&#x5929;&#x8981;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x63A5;&#x53E3;&#x8981;&#x6709;&#x4EC0;&#x4E48;&#x8BC9;&#x6C42;&#xFF08;<strong>&#x5373;&#x8981;&#x5B9E;&#x73B0;&#x4EC0;&#x4E48;&#x529F;&#x80FD;</strong>&#xFF09;&#x81EA;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x662F;&#x4E3A;&#x4E86;&#x66F4;&#x597D;&#x7684;&#x4F20;&#x9012;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x4F20;&#x9012;&#x7684;&#x503C;&#x3002;</p>
<ul>
<li><p>&#x5927;&#x5BB6;&#x90FD;&#x77E5;&#x9053;Recyclerview&#x6CA1;&#x6709;&#x81EA;&#x5E26;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;&#xFF0C;&#x4ECA;&#x5929;&#x5C31;&#x4EE5;Recyclerview&#x7684;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;&#x4E3A;&#x4F8B;&#xFF0C;&#x6765;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#x81EA;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;</p>
</li>
<li><p>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#x7C7B;<br>&#x200B;         </p>
<p> public interface OnItemClickListener {<br>   //&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x9002;&#x914D;&#x5668;&#x7684;item&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4F4D;&#x7F6E;</p>
<ul>
<li>&#x77ED;&#x6309;&#x4E8B;&#x4EF6;<br>void OnItemClick(View view,int position);<br>&#x957F;&#x6309;&#x4E8B;&#x4EF6;<br>void OnItemLongClick(View view,int position);<br>}</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="&#x5176;&#x6B21;"><a href="#&#x5176;&#x6B21;" class="headerlink" title="&#x5176;&#x6B21;"></a>&#x5176;&#x6B21;</h3><ul>
<li>&#x8981;&#x5B9E;&#x73B0;Recyclerview&#x7684;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;&#xFF0C;&#x5F53;&#x7136;&#x8981;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x9002;&#x914D;&#x5668;&#x4E86;</li>
</ul>
<pre><code>  public class CustomAdapter extends RecyclerView.Adapter
    &lt;CustomAdapter.CustomViewHolder&gt; {

   private List&lt;CustomBean&gt; mList;
   private Context mContext;
   private LayoutInflater mInflater;
   private OnItemClickListener mOnItemClickListener;

public CustomAdapter(List&lt;CustomBean&gt; mList, Context context) {
    this.mList = mList;
    this.mContext = context;
    this.mInflater = LayoutInflater.from(mContext);
}

@Override
public CustomViewHolder onCreateViewHolder(ViewGroup 
parent, int viewType) {
    View view = mInflater.inflate(R.layout.item_custom_layout, 
parent, false);
    CustomViewHolder viewHolder = new CustomViewHolder(view);
    return viewHolder;
}

@Override
public void onBindViewHolder( CustomViewHolder holder, int position) {
    holder.mTxtItemTitle.setText(mList.get(position).getTitle());
    holder.mTxtItemContent.setText(mList.get(position).getContent());
    //&#x8BBE;&#x7F6E;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;
   setUIEvent(holder);
}

@Override
public int getItemCount() {
    return mList==null?0:mList.size();
}

class CustomViewHolder extends RecyclerView.ViewHolder {

    TextView mTxtItemTitle, mTxtItemContent;

    public CustomViewHolder(View itemView) {
        super(itemView);
        mTxtItemTitle = itemView.findViewById(R.id.txt_item_title);
        mTxtItemContent = itemView.findViewById(R.id.txt_item_content);
    }
}

/**
 * &#x8BBE;&#x7F6E;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;
 * @param holder
 */
public void setUIEvent(final CustomViewHolder holder){
    //&#x70B9;&#x51FB;&#x4E8B;&#x5047;&#xFF0C;&#x9996;&#x5148;&#x5224;&#x65AD;&#x662F;&#x5426;&#x4E3A;&#x7A7A;&#xFF0C;&#x4E0D;&#x4E3A;&#x7A7A;&#x7684;&#x65F6;&#x5019;&#x518D;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;
    if (mOnItemClickListener != null) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int layoutPosition = holder.getLayoutPosition();
                mOnItemClickListener.OnItemClick(holder.itemView, layoutPosition);
            }
        });
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                int layoutPosition = holder.getLayoutPosition();
                mOnItemClickListener.OnItemLongClick(holder.itemView, layoutPosition);
                return false;
            }
        });
    }
}

/**
 * &#x63D0;&#x4F9B;&#x7ED9;Activity&#x6216;&#x8005;Fragment&#x8C03;&#x7528;&#x7684;
 *
 * @param onItemClickListener
 */
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
    this.mOnItemClickListener = onItemClickListener;
}
 }</code></pre><p><strong>&#x5728;&#x9002;&#x914D;&#x5668;&#x91CC;&#x9762;&#x5BF9;&#x63A5;&#x53E3;&#x7684;&#x8C03;&#x7528;&#x5DF2;&#x7ECF;&#x5F88;&#x6E05;&#x6670;&#x660E;&#x4E86;&#x4E86;&#xFF0C;&#x76F8;&#x4FE1;&#x5404;&#x4F4D;&#x770B;&#x5B98;&#x5DF2;&#x7ECF;&#x770B;&#x61C2;&#x4E86;&#x5427;&#x3002;</strong></p>
<h3 id="&#x518D;&#x6B21;"><a href="#&#x518D;&#x6B21;" class="headerlink" title="&#x518D;&#x6B21;"></a>&#x518D;&#x6B21;</h3><ul>
<li><p>&#x5F53;&#x7136;&#xFF0C;&#x73B0;&#x5728;&#x5C31;&#x662F;&#x5728;Activity&#x91CC;&#x9762;&#x600E;&#x4E48;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x56DE;&#x8C03;&#x4E86;</p>
<pre><code>public class ThirdActivity extends BaseActivity implements 
 OnItemClickListener{

 RecyclerView mRecyclerView;
 List&lt;CustomBean&gt;mList=new ArrayList&lt;&gt;();
 CustomAdapter mAdapter;

@Override
public void setContentView() {
  setContentView(R.layout.activity_third);
}

@Override
public void initView() {
  mRecyclerView = $(R.id.recyclerView);
  mRecyclerView.setLayoutManager(new 
LinearLayoutManager(this));
  mAdapter= new CustomAdapter(mList,this);
  mAdapter.setOnItemClickListener(this);
  mRecyclerView.setAdapter(mAdapter);

 }

 @Override
public void initData() {

  }

@Override
 public void initClick(View view) {

 }

@Override
public void setListener() {

}

@Override
public void OnItemClick(View view, int position) {
  ToastUtils.showMessage(this,getResources().getString(R.string.click_item));
}

@Override
public void OnItemLongClick(View view, int position) {

}
}</code></pre></li>
<li><p>&#x5230;&#x6B64;&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x5F62;&#x6210;&#x4E86;&#x4E00;&#x4E2A;&#x5706;&#x6EE1;&#x7684;&#x56DE;&#x8C03;&#xFF0C;&#x5F53;&#x7136;&#x8FD8;&#x6709;&#x5176;&#x4ED6;&#x56DE;&#x8C03;&#x5199;&#x6CD5;&#xFF0C;&#x518D;&#x4E3E;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x8BB2;&#x89E3;&#x4E00;&#x4E0B;&#x3002;&#x4F9D;&#x7136;&#x662F;&#x5728;&#x9002;&#x914D;&#x5668;&#x4E2D;&#x5B9E;&#x73B0;</p>
</li>
</ul>
<p><img src="http://upload-images.jianshu.io/upload_images/1716569-036829b6b279f332.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="&#x9002;&#x914D;&#x5668;&#x56FE;.png"></p>
<ul>
<li><p>&#x6765;&#x770B;&#x56FE;&#xFF0C;&#x8FD9;&#x4E2A;&#x5C31;&#x662F;&#x4E0A;&#x9762;&#x5B9E;&#x73B0;&#x7684;&#x9002;&#x914D;&#x5668;&#x56FE;&#x7247;&#xFF0C;&#x7136;&#x540E;&#x6211;&#x4EEC;&#x60F3;&#x5BF9;<strong>&#x5185;&#x5BB9;</strong>&#x8FD9;&#x4E2A;&#x5B57;&#x6BB5;&#x52A0;&#x4E0A;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;&#x8BE5;&#x600E;&#x4E48;&#x505A;&#x5462;&#xFF1F;&#x76F8;&#x4FE1;&#x806A;&#x660E;&#x5982;&#x4F60;&#x7684;&#x770B;&#x5B98;&#x5DF2;&#x7ECF;&#x60F3;&#x5230;&#x4E86;&#x3002;&#x5373;&#x5BF9;<strong>&#x5185;&#x5BB9;</strong>&#x8FD9;&#x4E2A;TextView&#x52A0;&#x4E0A;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;&#x5373;&#x53EF;&#xFF0C;&#x8BDD;&#x4E0D;&#x591A;&#x8BF4;&#x4E0A;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code>/**
  * &#x70B9;&#x51FB;&#x5185;&#x5BB9;&#x7684;&#x63A5;&#x53E3;
  */
public interface OnItemContentClickListener{
 //&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;
  void OnContentClick(int position);
  //&#x957F;&#x6309;&#x4E8B;&#x4EF6;
  void OnContentLongClick(int position);
}</code></pre></li>
<li><p>&#x7531;&#x4E0A;&#x9762;&#x7684;&#x63A5;&#x53E3;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x6B64;&#x63A5;&#x53E3;&#x4E3B;&#x8981;&#x5B9E;&#x73B0;&#x4E86;&#x70B9;&#x51FB;&#x5185;&#x5BB9;&#x533A;&#x57DF;&#x83B7;&#x53D6;&#x5185;&#x5BB9;&#x5BF9;&#x5E94;&#x7684;&#x4F4D;&#x7F6E;&#x7684;&#x6570;&#x636E;&#xFF08;&#x7136;&#x540E;&#x5B9E;&#x73B0;&#x8DF3;&#x8F6C;&#x529F;&#x80FD;&#x5373;&#x53EF;&#xFF09;</p>
<pre><code>/**
 * &#x70B9;&#x51FB;&#x5185;&#x5BB9;&#x90A3;&#x4E2A;TextView&#x5BF9;&#x5E94;&#x7684;&#x8C03;&#x7528;
 * @param onContentListener
 */
  public void setOnContentListener(OnItemContentClickListener 
onContentListener){
 this.mOnItemContentClickListener=onContentListener;
}</code></pre></li>
<li><p>&#x6700;&#x540E;&#x5728;Activity&#x4E2D;&#x8FDB;&#x884C;&#x8C03;&#x7528;&#x4E86;</p>
<pre><code> mAdapter.setOnContentListener(new 
CustomAdapter.OnItemContentClickListener() {</code></pre><p>  @Override<br> public void OnContentClick(int position) {<br>  ToastUtils.showMessage(ThirdActivity.this,<br> &#x200B;               getResources().getString(R.string.click_item_content));<br> &#x200B;    }</p>
<pre><code>    @Override
    public void OnContentLongClick(int position) {

    }
});</code></pre></li>
<li><p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x8FD9;&#x91CC;&#x662F;&#x91C7;&#x7528;&#x533F;&#x540D;&#x5185;&#x90E8;&#x6765;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x8FD9;&#x6837;&#x5199;&#x53EF;&#x4EE5;&#x66F4;&#x76F4;&#x89C2;&#x4E00;&#x70B9;&#xFF0C;&#x4F46;&#x662F;&#x770B;&#x7740;&#x6BD4;&#x8F83;&#x4E71;&#x4E00;&#x70B9;&#xFF08;&#x4EC1;&#x8005;&#x89C1;&#x4EC1;&#xFF0C;&#x667A;&#x8005;&#x89C1;&#x667A;&#xFF09;</p>
</li>
</ul>
<h3 id="&#x6700;&#x540E;"><a href="#&#x6700;&#x540E;" class="headerlink" title="&#x6700;&#x540E;"></a>&#x6700;&#x540E;</h3><ul>
<li>&#x5F53;&#x7136;&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x8FD8;&#x6709;&#x5F88;&#x591A;&#x5199;&#x6CD5;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x5927;&#x5BB6;&#x53BB;&#x63A2;&#x7D22;&#xFF0C;&#x6211;&#x8FD9;&#x91CC;&#x53EA;&#x662F;&#x629B;&#x7816;&#x5F15;&#x7389;&#x3002;<ul>
<li>&#x9488;&#x5BF9;&#x81EA;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x4ECA;&#x5929;&#x5C31;&#x8BB2;&#x5230;&#x8FD9;&#x91CC;&#xFF0C;&#x5E0C;&#x671B;&#x5BF9;&#x5927;&#x5BB6;&#x6709;&#x6240;&#x5E2E;&#x52A9;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x54EA;&#x91CC;&#x8BB2;&#x7684;&#x4E0D;&#x5230;&#x4F4D;&#x7684;&#x5730;&#x65B9;&#xFF0C;&#x8FD8;&#x8BF7;&#x5927;&#x5BB6;&#x89C1;&#x8C05;&#xFF0C;&#x5E76;&#x4E14;&#x544A;&#x8BC9;&#x6211;&#x4E00;&#x58F0;&#xFF0C;&#x8C22;&#x8C22;&#x3002;</li>
</ul>
</li>
</ul>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/08/21/Android 装饰者模式初探/" rel="next" title="Android 装饰者模式初探">
                <i class="fa fa-chevron-left"></i> Android 装饰者模式初探
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/08/21/Android-DatePicker/" rel="prev" title="Android DatePicker">
                Android DatePicker <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Silence潇湘夜雨</p>
              <p class="site-description motion-element" itemprop="description">Android开发一枚</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">55</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/muyishuangfeng" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/1e2eec6f972c" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/58df0abf61ff4b006b115e43" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-star"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://twitter.com/yangke20792452" target="_blank" title="Twitter">
                      
                        <i class="fa fa-fw fa-twitter"></i>Twitter</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#前提"><span class="nav-number">1.</span> <span class="nav-text">前提</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其次"><span class="nav-number">2.</span> <span class="nav-text">其次</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#再次"><span class="nav-number">3.</span> <span class="nav-text">再次</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最后"><span class="nav-number">4.</span> <span class="nav-text">最后</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Silence潇湘夜雨</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">114.8k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

  <!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618},"display":{"superSample":2,"width":150,"height":300,"position":"right","hOffset":0,"vOffset":-20},"mobile":{"show":false},"react":{"opacityDefault":0.5,"opacityOnHover":0.5},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
